<template>
	<sc-dialog
		v-model="visible"
		show-fullscreen
		destroy-on-close
		:title="titleMap[mode]"
		width="750px"
		@close="close"
	>
		<el-form
			ref="formRef"
			label-width="100px"
			:model="formData"
			:rules="rules"
		>
			<el-row><el-col :span="12"> 
<el-form-item label="订单编号" prop="number"> 
	<el-input 
		v-model="formData.number" 
		placeholder="请输入订单编号" 
		:maxlength="50" 
		show-word-limit 
		clearable 
	></el-input> 
</el-form-item> 
</el-col> 
<el-col :span="12"> 
<el-form-item label="客户ID" prop="customerId"> 
	<el-input 
		v-model="formData.customerId" 
		placeholder="请输入客户ID" 
		:maxlength="20" 
		show-word-limit 
		clearable 
	></el-input> 
</el-form-item> 
</el-col> 
<el-col :span="12"> 
<el-form-item label="负责人" prop="userId"> 
	<el-input 
		v-model="formData.userId" 
		placeholder="请输入负责人" 
		:maxlength="20" 
		show-word-limit 
		clearable 
	></el-input> 
</el-form-item> 
</el-col> 
<el-col :span="12"> 
<el-form-item label="下单时间" prop="orderDate"> 
	<el-input 
		v-model="formData.orderDate" 
		placeholder="请输入下单时间" 
		:maxlength="0" 
		show-word-limit 
		clearable 
	></el-input> 
</el-form-item> 
</el-col> 
<el-col :span="12"> 
<el-form-item label="订单总额" prop="totalAmount"> 
	<el-input 
		v-model="formData.totalAmount" 
		placeholder="请输入订单总额" 
		:maxlength="15" 
		show-word-limit 
		clearable 
	></el-input> 
</el-form-item> 
</el-col> 
<el-col :span="12"> 
<el-form-item label="已收金额" prop="paidAmount"> 
	<el-input 
		v-model="formData.paidAmount" 
		placeholder="请输入已收金额" 
		:maxlength="15" 
		show-word-limit 
		clearable 
	></el-input> 
</el-form-item> 
</el-col> 
<el-col :span="12"> 
<el-form-item label="是否开票" prop="invoiceStatus"> 
	<el-input 
		v-model="formData.invoiceStatus" 
		placeholder="请输入是否开票" 
		:maxlength="1" 
		show-word-limit 
		clearable 
	></el-input> 
</el-form-item> 
</el-col> 
</el-row>
		</el-form>

		<template #footer>
			<el-button @click="close">取 消</el-button>
			<el-button :loading="isSaveing" type="primary" @click="save">
				确 定
			</el-button>
		</template>
	</sc-dialog>
</template>
<script>
export default {
    emits: ['complete'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: "新增",
				edit: "编辑",
			},
			isSaveing: false,
			visible: false,
			formData: {
				id: 0,
				number:undefined, 
customerId:undefined, 
userId:undefined, 
orderDate:undefined, 
totalAmount:undefined, 
paidAmount:undefined, 
invoiceStatus:undefined, 

			},
			rules: {number: [{required: true,message: "请输入订单编号",trigger: "blur",},],customerId: [{required: true,message: "请输入客户ID",trigger: "blur",},],userId: [{required: true,message: "请输入负责人",trigger: "blur",},],totalAmount: [{required: true,message: "请输入订单总额",trigger: "blur",},],},
			
		};
	},
	mounted() {
	},
	methods: {
		async open(row) {
			if (!row) {
				this.mode = "add";
			} else {
				this.mode = "edit";
				var res = await this.$API.erpsalesorder.model.get(row.id);
				this.formData = res.data;
			}
			this.visible = true;
		},
		save() {
			this.$refs.formRef.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					let res = null;
					if (this.formData.id === 0) {
						res = await this.$API.erpsalesorder.add.post(this.formData);
					} else {
						res = await this.$API.erpsalesorder.update.put(this.formData);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit("complete");
						this.visible = false;
						this.$message.success("保存成功");
					} else {
						this.$alert(res.message, "提示", { type: "error" });
					}
				}
			});
		},
		close() {
			this.formData = {
				id: 0,
				number:undefined, 
customerId:undefined, 
userId:undefined, 
orderDate:undefined, 
totalAmount:undefined, 
paidAmount:undefined, 
invoiceStatus:undefined, 

			};
			this.$refs.formRef.resetFields();
			this.visible = false;
		},
	},
};
</script>
